load("experiment-data.RData")
attach(experimental.dataset)

#######################
# Figure 4, top panel #
#######################

# Difference of out-partisans and co-partisans in policy condition (0.66), with CIs around difference
t.test(binaryreelection[(treatment=="R Policy" & PID=="R") | (treatment=="D Policy" & PID=="D")], 
       binaryreelection[(treatment=="R Policy" & PID=="D") | (treatment=="D Policy" & PID=="R")])

# Difference of out-partisans and co-partisans in non-policy condition (0.27), with CIs around difference
t.test(binaryreelection[(treatment=="R Credit" & PID=="R") | (treatment=="D Credit" & PID=="D")], 
       binaryreelection[(treatment=="R Credit" & PID=="D") | (treatment=="D Credit" & PID=="R")])

# Difference of independents and co-partisans in policy condition (0.35), with CIs around difference
t.test(binaryreelection[(treatment=="R Policy" & PID=="R") | (treatment=="D Policy" & PID=="D")], 
       binaryreelection[(treatment=="R Policy" & PID=="I") | (treatment=="D Policy" & PID=="I")])

# Difference of independents and co-partisans in non-policy condition (0.18), with CIs around difference
t.test(binaryreelection[(treatment=="R Credit" & PID=="R") | (treatment=="D Credit" & PID=="D")], 
       binaryreelection[(treatment=="R Credit" & PID=="I") | (treatment=="D Credit" & PID=="I")])

par(mar=c(4.5,6,1,1), mgp=c(1.5,.25,0))
means <- c(0.664, 0.267) # for copartisans vs. opposite partisans
upper.bound <- c(0.734,0.338)
lower.bound <- c(0.595,0.196)
group <- c(2.1,1.9) # for placement on plot
plot(means,group,xlim=c(0,1),ylim=c(.5,2.5), tck=0, cex.main=1, main="", cex.lab=1, cex.axis=1, 
     pch=16, cex=1.5, ylab="", xaxt="n", yaxt="n", xlab="Differences in support",col=c("BLACK","GRAY"))
title(main="Differences in Average Senator Support", cex.main=1)
axis(1,at=c(0,0.25,0.5,0.75,1),cex.axis=1,labels=c("0","0.25","0.5","0.75","1"),tck=0)
segments(lower.bound, group, upper.bound, group,col=c("BLACK","GRAY"))
ind.means <- c(.348,.176) # for copartisans vs. independents
ind.upper <- c(.47,.276)
ind.lower <- c(.226,.076)
points(ind.means,group-1,cex=1.5,pch=16,col=c("BLACK","GRAY"))
segments(ind.upper,group-1,ind.lower,group-1,col=c("BLACK","GRAY"))
par(mgp=c(2,.1,0))
axis(2, at=c(2,1), las=2, cex.axis=.9,labels=c("Copartisans \n     vs.       \n Opposite   \n partisans   ", "Copartisans  \n     vs.        \n Independents"),tck=0)
text(.267,2,"0.27",cex=.9)
text(.664,2.2,"0.66",cex=.9)
text(.176,1,"0.18",cex=.9)
text(.348,1.2,"0.35",cex=.9)
legend("bottomright",c("Policy emphasis","Non-policy emphasis"),pch=16,cex=1,
       lty=1,pt.cex=1.25,
       lwd=1,col=c("BLACK","GRAY"))


##########################
# Figure 4, bottom panel #
##########################

# Differential treatment effect for copartisans (0.02), with CIs around difference
t.test(binaryreelection[(treatment=="R Credit" & PID=="R") | (treatment=="D Credit" & PID=="D")],
       binaryreelection[(treatment=="R Policy" & PID=="R") | (treatment=="D Policy" & PID=="D")])

# Differential treatment effect for opposite partisans (0.42), with CIs around difference
t.test(binaryreelection[(treatment=="R Credit" & PID=="D") | (treatment=="D Credit" & PID=="R")],
       binaryreelection[(treatment=="R Policy" & PID=="D") | (treatment=="D Policy" & PID=="R")])

# Differential treatment effect for independents (0.19), with CIs around difference
t.test(binaryreelection[(treatment=="R Credit" & PID=="I") | (treatment=="D Credit" & PID=="I")],
       binaryreelection[(treatment=="R Policy" & PID=="I") | (treatment=="D Policy" & PID=="I")])

par(mar=c(4.5,6,1,1), mgp=c(1.5,.25,0))
means <- c(0.022,.419,.194)
upper.bound <- c(.069,.506,.343)
lower.bound <- c(-.026,.332,.045)
group <- c(3,2,1)
plot(means,group,xlim=c(-0.1,.6),ylim=c(.5,3.5), tck=0, cex.main=1, main="", cex.lab=1, cex.axis=1,
     pch=16, cex=1.5, ylab="", xaxt="n", yaxt="n", xlab="Increase in support")
title(main="Treatment Effects by Partisanship", cex.main=1)
axis(1,at=c(0,0.2,0.4,0.6),cex.axis=1,labels=c("0","0.2","0.4","0.6"),tck=0)
segments(lower.bound, group, upper.bound, group)
abline(v=0,lty=2)
par(mgp=c(2,.1,0))
axis(2, at=c(3,2,1), las=2, cex.axis=.9,labels=c("Copartisans","Opposite\n partisans","Independents"),tck=0)
text(.025,3.15,"0.02",cex=.9)
text(.419,2.15,"0.42",cex=.9)
text(.194,1.15,"0.19",cex=.9)

############
# Figure 5 #
############

# Difference in reported importance of policy and non-policy considerations for those treated with policy
t.test(legislative.binary[treatment %in% c("R Policy","D Policy")] - funding.binary[treatment %in% c("R Policy","D Policy")])

# Difference in reported importance of policy and non-policy considerations for those treated with non-policy
t.test(legislative.binary[treatment %in% c("R Credit","D Credit")] - funding.binary[treatment %in% c("R Credit","D Credit")])

# Difference in difference
t.test(((legislative.binary[treatment %in% c("R Policy","D Policy")] - funding.binary[treatment %in% c("R Policy","D Policy")])),
       ((legislative.binary[treatment %in% c("R Credit","D Credit")] - funding.binary[treatment %in% c("R Credit","D Credit")])))

par(mar=c(4.5,6,1,1), mgp=c(1.5,.25,0))
means <- c(0.15337423,0.09807692)
upper.bound <- c(0.1950766,0.13314574)
lower.bound <- c(0.1116719,0.06300811)
group <- c(2,1)
plot(means,group,xlim=c(0,.2),ylim=c(.5,2.5), tck=0, cex.main=1, main="", cex.lab=1, cex.axis=1.15, 
     pch=16, cex=1.5, ylab="", xaxt="n", yaxt="n", xlab="Difference in reported importance of policy and non-policy considerations")
axis(1,at=c(0,0.05,0.1,0.15,.2),cex.axis=1.15,labels=c("0","0.05","0.1","0.15",".2"),tck=0)
segments(lower.bound, group, upper.bound, group)
par(mgp=c(2,.1,0))
axis(2, at=c(2,1), las=2, cex.axis=1.15,labels=c("Policy \n Treatment","Non-Policy \n Treatment"),tck=0)
text(0.15,2.1,"0.15",cex=1)
text(0.10,0.9,"0.10",cex=1)
lines(x=c(.1,.15),y=c(1,2), lty=2)
text(.17,1.4,"Difference = 0.05 \n (p=0.046)",cex=1)
